<template>
  <div class="app-container">    
    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body @close="cancel">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="公告标题" prop="title">
            <el-input v-model="form.title" placeholder="请输入公告标题" readonly/>
        </el-form-item>
        <el-form-item label="公告内容" prop="content">
            <div v-html="form.content"></div>
        </el-form-item>
        <el-form-item label="发布部门" prop="depart">
            <el-input v-model="form.depart" placeholder="请输入公告标题" readonly/>
        </el-form-item>
        <el-form-item label="发布时间" prop="publish_time">
            <el-input v-model="form.publish_time" placeholder="请输入公告标题" readonly/>
        </el-form-item>
        <el-form-item label="图片" prop="imgs" v-if="form.imgs">
            <image-preview :src="form.imgs" :width="50" :height="50"/>
        </el-form-item>
        <el-form-item label="附件" prop="files" v-if="form.files">
            <file-preview :files="form.files" :width="50" :height="50"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { apiGet} from "@/api/openapi";

export default {
  name: "NoticeView",
  props:{
      noticeId: Number
  },
  data() {
    return {
        open: false,
        title: '校园公告',
      // 表单参数
      form: {}
    };
  },
  watch: {
    noticeId: {
      deep: true,
      handler(val) {
          if(val == null){
              this.open = false;
              return;
          }else{
        this.getNotice(val)
          }
      }
    }
  },
  created() {
      if(this.noticeId){
          this.getNotice(this.noticeId);
      }
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.$emit('close');
    },
    /** 查询数据 */
    getNotice(noticeId) {
      let data = {"@table":"school_notice", id:noticeId};
      apiGet(data).then(response => {
          this.open = true;
        this.form = response.data;
      });
    }
  }
};
</script>
